package ServerSocket2;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * Created by 旧 on 2018/8/11.
 */
public class xiaozhuzhu extends Thread{
    Scanner scanner=new Scanner(System.in);
    Socket cliet=null;
    @Override
    public void run(){
        try {
            //3.创建读写流
            InputStream input = cliet.getInputStream();
            OutputStream out = cliet.getOutputStream();
            //4.创建一个具体的高效的读取流
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(input));
            ObjectInputStream objectInput=new ObjectInputStream(input);
            User user=(User) objectInput.readObject();


            while (true){
                //5.读取一次信息
                String line = bufferedReader.readLine();
                System.out.println(user.name+"发来：\t" + line);
                if (line.equals("bye")){
                    break;
                }

                //6.回复一次信息
                System.out.println("请输入回复信息");
                String an=scanner.next();
                out.write((an+"\n").getBytes());
            }
            //7.关闭
            bufferedReader.close();
            input.close();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
}
